/**
 * Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 * For the applicable distribution terms see the license.txt -file, included in
 * the distribution.
 */

#ifndef GEAUDIOOUT_H
#define GEAUDIOOUT_H

#include <QThread>
#include "GEInterfaces.h"

// Forward declarations
class QAudioOutput;
class QIODevice;


/**
 * Uncomment the following define to enable a very ugly hack to set the volume
 * level on Symbian devices higher. By default, on Symbian, the volume level
 * is very low when audio is played using QAudioOutput class. For now, this
 * ugly hack is the only way to set the volume louder.
 *
 * WARNING: The volume hack (see the .cpp file) is VERY DANGEROUS because the
 * data to access the volume interface is retrieved manually with pointer
 * manipulation. Should the library, in which the interface is implemented,
 * be modified even a tiny bit, the application using this hack might crash.
 */
//#define QTGAMEENABLER_USE_VOLUME_HACK


namespace GE {

class AudioOut : public QThread
{
    Q_OBJECT

public: // Data types

    enum ThreadStates {
        NotRunning = 0,
        DoRun = 1,
        DoExit = 2
    };

public:
    AudioOut(AudioSource *source, QObject *parent = 0);
    virtual ~AudioOut();

public:
    bool usingThead() const { return m_usingThread; }

public slots:
    void tick();

private slots:
    void audioNotify();

protected: // From QThread
     virtual void run(); // For the threaded mode only!

protected: // Data
    QAudioOutput *m_audioOutput; // Owned
    QIODevice *m_outTarget; // Not owned
    AudioSource *m_source; // Not owned
    AUDIO_SAMPLE_TYPE *m_sendBuffer; // Owned
    int m_sendBufferSize;
    qint64 m_samplesMixed;
    int m_threadState;
    bool m_usingThread;
};

} // namespace GE

#endif // GEAUDIOOUT_H
